#ifndef _EPOLL_HANDLER_H_20170315
#define _EPOLL_HANDLER_H_20170315

#include <sys/epoll.h>
#include <stdlib.h>
#include <string.h>

#define EPOLLEVENTS 128
#define FDSIZE		100
#define TIMEOUT		1000

class EpollHandler
{
private:
	int epollFd;
	struct epoll_event *events;

public:
	EpollHandler():epollFd(0){
		events = (epoll_event*)malloc(sizeof(epoll_event)*EPOLLEVENTS);
		memset(events, 0, sizeof(epoll_event) * EPOLLEVENTS);
	}

	bool EpollInit();
	void EpollUinit();
	//IO多路复用, 返回epoll_wait得到的event个数
	int WaitEpoll();
	//关闭epollfd
	void CloseEpoll();
	//添加时间
	bool AddEvent(int fd, int state);
	//修改事件
	bool ModifyEvent(int fd, int state);
	//删除事件
	bool DeleteEvent(int fd, int state);
	//是否为读时间
	int CheckInEvent(int num);
	//是否为写时间
	int CheckOutEvent(int num);

private:
	bool CtlEvent(int action, int fd, int state);
	//获取epoll事件
	int CheckEvent(int num, int action);
};

#endif
